package net.zhengxinyun.performance.service.setTime;

import net.zhengxinyun.performance.entity.SetTimeEntity;
import net.zhengxinyun.performance.filter.SetTimeFilter;
import net.zhengxinyun.performance.mapper.setTime.SetTimeEntityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SetTimeServiceImpl implements SetTimeService {


    private SetTimeEntityMapper setTimeEntityMapper;

    @Autowired
    public SetTimeServiceImpl(SetTimeEntityMapper setTimeEntityMapper) {
        this.setTimeEntityMapper = setTimeEntityMapper;
    }

    /**
     * 更新填写时间段设置
     *
     * @param filter
     */
    @Override
    public String updateTime(SetTimeFilter filter) {
        if (filter.getIndexClass() != null && !"".equals(filter.getIndexClass())) {
            SetTimeEntity entity = setTimeEntityMapper.selectByType(filter.getIndexClass());
            int i = 0;
            if (entity != null) {
                i = setTimeEntityMapper.updateSetTime(filter);
            } else {
                i = setTimeEntityMapper.creatSetTime(filter);
            }
            if (i == 0)
                return "更新失败";
        }
        return "更新成功";
    }

    @Override
    public SetTimeEntity findByIndexClass(String indexClass) {

        return setTimeEntityMapper.selectByType(indexClass);
    }
}
